<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\v1\controller;

use api\v1\model\Advertise;
use api\v1\model\Article;
use api\v1\model\Category;
use api\v1\model\Product;
use cmf\controller\RestBaseController;
use cmf\controller\RestUserBaseController;

/**
 * 首页接口
 * Class IndexController
 * @package api\v1\controller
 */
class CategoryController extends RestUserBaseController
{

    public function index() {
        $data = [];
        $data['list'] = Category::with("products")->where("type",1)->order("sort desc")->select();
        $this->success("ok",$data);
    }
    public function products() {
        $cid = $this->request->param('cat_id');
        $res = Product::where("category_id",$cid)
            ->order('sort','desc')
            ->paginate(20);
        $this->success("ok",['list'=>$res->items()]);
    }

}
